<template>
	<view class="page bg-fff">
		<up-gap height="20"></up-gap>

		<view class="title font15 fontBold">{{ detailData.title + '  摇号结果' }}</view>
		<view class="font12 col-grey top-10 bottom-20">{{ detailData.gong_time }}</view>

		<view class="yaoImgWrap" v-if="detailData.yao_rules?.length > 0">
			<block v-for="(item, index) in detailData.yao_rules" :key="index">
				<image class="imgItem" :src="item.url" mode="widthFix" :lazy-load="true" @click="clickImg(index)"></image>
			</block>
		</view>
		<up-gap height="40"></up-gap>
	</view>
</template>

<script setup>
import { ref } from "vue";
import { useUserInfoStore } from '@/store/index';
import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
import { getYaoHaoDetailAPI } from '@/common/api/houses';

const userInfoStore = useUserInfoStore();

let pan_id = ref('');
let detailData = ref({});


// 页面加载
onLoad((options) => {
	pan_id.value = options.panId;
	uni.$check_and_login(init)
})

// 分享到好友
onShareAppMessage(() => {
	return {
		title: detailData.title + '摇号公示' || '摇号公示',
		path: `/pages/products/yao-hao-gong-shi/detail/index?panId=${pan_id.value}&puid=${userInfoStore.userInfo.id}`,
	}
})

// 分享到朋友圈
onShareTimeline(() => {
	return {
		title: detailData.title + '摇号公示' || '摇号公示',
		query: `panId=${pan_id.value}&puid=${userInfoStore.userInfo.id}`
	}
})

//初始化
async function init() {
	try {
		const res = await getYaoHaoDetailAPI(pan_id.value);
		if(res.status !== 0) {
			uni.$u.toast(res.detail);
			return
		}
		uni.setNavigationBarTitle({
			title: `${res.detail.title}  摇号结果`
		});
		detailData.value = res.detail;
	} catch (error) {}
}

// 点击图片
function clickImg(index) {
	const urls = detailData.value.yao_rules.map(item => item.url);
	uni.previewImage({
		urls: urls,
		current: index
	});
}
</script>

<style lang="scss" scoped>
.page{
	min-height: 100vh;
	overflow: hidden;
	padding: 0 30rpx;
	.yaoImgWrap{
		font-size: 0;
		.imgItem{
			width: 100%;
		}
	}
}
</style>